import { Controller, Get, Post, Body, Patch, Param, Delete, Query } from "@nestjs/common";
import { DictService } from "./dict.service";
import { CreateSysDictDto } from "./dto/create-sys-dict.dto";
import { UpdateSysDictDto } from "./dto/update-sys-dict.dto";
import { ApiBearerAuth, ApiOperation, ApiTags } from "@nestjs/swagger";
import { FindListSysDictDto } from "@/modules/system/dict/dto/find-list-sys-dict.dto";
import { FindDictByCodeDto } from "@/modules/system/dict/dto/find-dict-by-code.dto";
import { NotToken } from "@/decorators/not-token.decorator";

@Controller("system/dict")
@ApiTags("业务字典")
@ApiBearerAuth()
export class DictController {
    constructor(private readonly dictService: DictService) {
    }
    
    @Post()
    @ApiOperation({ summary: "创建字典" })
    create(@Body() createSysDictDto: CreateSysDictDto) {
        return this.dictService.create(createSysDictDto);
    }
    
    @Get()
    @ApiOperation({ summary: "查询字典列表" })
    findAll(@Query() findAllDto: FindListSysDictDto) {
        return this.dictService.findAll(findAllDto);
    }
    
    @Get("findDictByCode")
    @ApiOperation({ summary: "更具编号查询字典列表" })
    @NotToken()
    findDictByCode(@Query() findDictByCodeDto: FindDictByCodeDto) {
        return this.dictService.findDictByCode(findDictByCodeDto);
    }
    
    @Get(":id")
    findOne(@Param("id") id: string) {
        return this.dictService.findOne(+id);
    }
    
    @Patch(":id")
    update(@Param("id") id: string, @Body() updateSysDictDto: UpdateSysDictDto) {
        return this.dictService.update(+id, updateSysDictDto);
    }
    
    @Delete(":id")
    remove(@Param("id") id: string) {
        return this.dictService.remove(+id);
    }
}
